//项目的全局前置守卫
//1引入路由
import router from "./router";
//引入cookie
import { getCookie } from "@/utils/support.js";
//2将不需要守卫的路由放到白名单
const whiteList = ["/login"];
//3路由守卫
router.beforeEach((to, from, next) => {
   console.log("路由守卫触发了",to,from,next);
   //1.判断登录状态
   if(getCookie("token")){//已经登录登录
    //2.如果路由是登录页，默认跳转到首页
    if(to.path == "/login"){
        next("/home");

    }else{
        next();
    }

   }else{
       //没有登录
       if(whiteList.indexOf(to.path) != -1){
           //在白名单中找到了该路由
           //放行
           next();
       }else{
           //没在白名单
           next("/login");
       }
   }
})